import { recursiveOf, take, forever, filter } from "./util"
import  { complex,add,multiply,Complex,sqrt } from "mathjs"

const abs = (c:Complex) => sqrt(c.re*c.re + c.im * c.im)
const mandelbrot = (init:Complex)=>(z:Complex,) =>{
    return add(multiply(z,z),init) as Complex
}

const m = recursiveOf(mandelbrot(complex(-1,-0.5)),complex(0,0))
take(10)(m()).forEach(x=>console.log(abs(x)))
take(10)((filter((v:Complex)=> abs(v)<2,m()))).forEach(x=>console.log(x))
